package com.wedata.腾讯;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.wedata.HttpUtils;

import java.util.*;

public class 企业微信标签 {

    public static void main(String[] args) {
        System.out.println(new Date(1745205386000L));
        //tagList();
    }
    /**
     * 标签库列表
     */
    public static void tagList0() {
        JSONObject body = new JSONObject();
        JSONObject resultStr = HttpUtils.sendPost("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get?external_userid=wmccZ9HAAARynaggd0WOVmcxWkCcSmCg&access_token=" + 企业微信.postRequestWithSign(), body);
        //{"errcode":0,"errmsg":"ok","follow_user":[{"createtime":1725256766,"description":"","remark":"T.","userid":"YangLin","tags":[{"group_name":"来源App标签同步1","tag_name":"产后肥胖","type":1,"tag_id":"etccZ9HAAAVI_12YddH9A3PfgiAl5PZA"},{"group_name":"来源App标签同步1","tag_name":"偏好米面食物早餐","type":1,"tag_id":"etccZ9HAAAiMvp8imPqGRgwSqbXwPalQ"},{"group_name":"来源App标签同步1","tag_name":"喝酒","type":1,"tag_id":"etccZ9HAAAACOUnSesfHTjEELrHIl4cA"},{"group_name":"来源App标签同步1","tag_name":"情绪性进食","type":1,"tag_id":"etccZ9HAAAzLalDmTtgw8lpQ9Ri42qOg"},{"group_name":"来源App标签同步1","tag_name":"手脚冰凉","type":1,"tag_id":"etccZ9HAAAaPINf_hNSGZSwqQKrDwfqA"},{"group_name":"来源App标签同步1","tag_name":"有特殊用药史","type":1,"tag_id":"etccZ9HAAAjgrVo1pJ6zEs3gJZk6xR3A"},{"group_name":"来源App标签同步1","tag_name":"有补剂需求","type":1,"tag_id":"etccZ9HAAAMeuvciRPHObYCOt1AX6qCg"},{"group_name":"来源App标签同步1","tag_name":"服激素类药","type":1,"tag_id":"etccZ9HAAAy2q_9PnEm1C68B1Rwo5NqA"},{"group_name":"来源App标签同步1","tag_name":"正常","type":1,"tag_id":"etccZ9HAAAjzcdu2b3tAw2NAFdu4HXRg"},{"group_name":"来源App标签同步1","tag_name":"爱吃盐味碳水类零食（薯片、辣条）","type":1,"tag_id":"etccZ9HAAAHV7mPJSc1vMWxurqe_Ha1w"},{"group_name":"来源App标签同步1","tag_name":"甲状腺疾病","type":1,"tag_id":"etccZ9HAAAxNEr2nM9goraAXnhqrACpA"},{"group_name":"来源App标签同步1","tag_name":"糖尿病","type":1,"tag_id":"etccZ9HAAAcu30OXX69t0SiMSvOgNABA"},{"group_name":"来源App标签同步1","tag_name":"素食主义者","type":1,"tag_id":"etccZ9HAAAZ1bIVCZpOcBtJ7KRUr_byA"},{"group_name":"来源App标签同步1","tag_name":"经常外食","type":1,"tag_id":"etccZ9HAAAg4sjw8WIofw4Mph7iHAKUg"},{"group_name":"来源App标签同步1","tag_name":"继发性肥胖","type":1,"tag_id":"etccZ9HAAAPGnWKBu2re56ME2wD212_g"},{"group_name":"来源App标签同步1","tag_name":"遗传性肥胖","type":1,"tag_id":"etccZ9HAAAIKtmydaWG-7S0BwbcqR5bA"},{"group_name":"来源App标签同步1","tag_name":"饮食不规律","type":1,"tag_id":"etccZ9HAAAtNasBp_IPYdFfphFVYoDzA"},{"group_name":"来源App标签同步2","tag_name":"体内激素失衡","type":1,"tag_id":"etccZ9HAAA9aOnamyG2uh95R43pOaWNQ"},{"group_name":"来源App标签同步2","tag_name":"普通慢性疾病","type":1,"tag_id":"etccZ9HAAAMXahRpzdoaVWuh7g7ubktA"},{"group_name":"来源App标签同步1","tag_name":"18.5≤BMI<24","type":1,"tag_id":"etccZ9HAAAtM130Q1IfEnX93uff55hbw"},{"group_name":"来源App标签同步1","tag_name":"18～22岁","type":1,"tag_id":"etccZ9HAAAOE42NKKv7Lu2SEAWqNgsug"},{"group_name":"来源App标签同步1","tag_name":"22～27岁","type":1,"tag_id":"etccZ9HAAAM6_d1HhZfR63jp9KEP4btw"},{"group_name":"来源App标签同步1","tag_name":"iPhone","type":1,"tag_id":"etccZ9HAAA6A9uHX3bQQjoydwjwc-x2Q"},{"group_name":"来源App标签同步1","tag_name":"久坐","type":1,"tag_id":"etccZ9HAAACs9XtoAtXy_LhpbD4ld4qg"},{"group_name":"来源App标签同步1","tag_name":"腰腹脂肪多","type":1,"tag_id":"etccZ9HAAA4AQE0CvtPjNQb1VanKBYKw"},{"group_name":"来源App标签同步1","tag_name":"非常需要监督","type":1,"tag_id":"etccZ9HAAAwQfubgR2sP1BwgeFd4sWnA"},{"group_name":"来源App标签同步2","tag_name":"n-3脂肪酸不足","type":1,"tag_id":"etccZ9HAAAX3StjFNPxdDrWbl7ukJujA"},{"group_name":"来源App标签同步2","tag_name":"不吃鱼虾贝类","type":1,"tag_id":"etccZ9HAAAqxF-FJ7NSLpVDfPYkkjLOA"},{"group_name":"来源App标签同步2","tag_name":"不吃鸡蛋","type":1,"tag_id":"etccZ9HAAA1snG8QlZAatY1KhD6oRhvA"},{"group_name":"来源App标签同步2","tag_name":"吃饭过快","type":1,"tag_id":"etccZ9HAAArxUsI2Xquk58CviXgl8WOw"},{"group_name":"来源App标签同步2","tag_name":"姨妈问题","type":1,"tag_id":"etccZ9HAAAXTsAFru6uJVOW_vyWgveDA"},{"group_name":"来源App标签同步2","tag_name":"常吃零食","type":1,"tag_id":"etccZ9HAAA2eanBIVvSZshMaYXLr09Ig"},{"group_name":"来源App标签同步2","tag_name":"有体检","type":1,"tag_id":"etccZ9HAAAuKjl_FvvsUsqOXkab0xXhQ"},{"group_name":"来源App标签同步2","tag_name":"蛋白质不足","type":1,"tag_id":"etccZ9HAAA8sSFWEuaOopMCoAYfIsNnw"},{"group_name":"来源App标签同步2","tag_name":"健萌会员","type":1,"tag_id":"etccZ9HAAAEditzbuq7DQG4h2cJe-yig"}],"remark_mobiles":[],"oper_userid":"wmccZ9HAAAkleVd3k8jAMk-egp4BYLZg","add_way":1},{"createtime":1727073192,"description":"","remark":"T.","userid":"ollie","tags":[{"group_name":"来源App标签同步1","tag_name":"产后肥胖","type":1,"tag_id":"etccZ9HAAAVI_12YddH9A3PfgiAl5PZA"},{"group_name":"来源App标签同步1","tag_name":"偏好米面食物早餐","type":1,"tag_id":"etccZ9HAAAiMvp8imPqGRgwSqbXwPalQ"},{"group_name":"来源App标签同步1","tag_name":"喝酒","type":1,"tag_id":"etccZ9HAAAACOUnSesfHTjEELrHIl4cA"},{"group_name":"来源App标签同步1","tag_name":"少眠","type":1,"tag_id":"etccZ9HAAA_-nb7zK7L5hMtJI8oiTYyg"},{"group_name":"来源App标签同步1","tag_name":"情绪性进食","type":1,"tag_id":"etccZ9HAAAzLalDmTtgw8lpQ9Ri42qOg"},{"group_name":"来源App标签同步1","tag_name":"手脚冰凉","type":1,"tag_id":"etccZ9HAAAaPINf_hNSGZSwqQKrDwfqA"},{"group_name":"来源App标签同步1","tag_name":"有特殊用药史","type":1,"tag_id":"etccZ9HAAAjgrVo1pJ6zEs3gJZk6xR3A"},{"group_name":"来源App标签同步1","tag_name":"有补剂需求","type":1,"tag_id":"etccZ9HAAAMeuvciRPHObYCOt1AX6qCg"},{"group_name":"来源App标签同步1","tag_name":"服激素类药","type":1,"tag_id":"etccZ9HAAAy2q_9PnEm1C68B1Rwo5NqA"},{"group_name":"来源App标签同步1","tag_name":"正常","type":1,"tag_id":"etccZ9HAAAjzcdu2b3tAw2NAFdu4HXRg"},{"group_name":"来源App标签同步1","tag_name":"爱吃盐味碳水类零食（薯片、辣条）","type":1,"tag_id":"etccZ9HAAAHV7mPJSc1vMWxurqe_Ha1w"},{"group_name":"来源App标签同步1","tag_name":"甲状腺疾病","type":1,"tag_id":"etccZ9HAAAxNEr2nM9goraAXnhqrACpA"},{"group_name":"来源App标签同步1","tag_name":"糖尿病","type":1,"tag_id":"etccZ9HAAAcu30OXX69t0SiMSvOgNABA"},{"group_name":"来源App标签同步1","tag_name":"素食主义者","type":1,"tag_id":"etccZ9HAAAZ1bIVCZpOcBtJ7KRUr_byA"},{"group_name":"来源App标签同步1","tag_name":"经常外食","type":1,"tag_id":"etccZ9HAAAg4sjw8WIofw4Mph7iHAKUg"},{"group_name":"来源App标签同步1","tag_name":"继发性肥胖","type":1,"tag_id":"etccZ9HAAAPGnWKBu2re56ME2wD212_g"},{"group_name":"来源App标签同步1","tag_name":"遗传性肥胖","type":1,"tag_id":"etccZ9HAAAIKtmydaWG-7S0BwbcqR5bA"},{"group_name":"来源App标签同步1","tag_name":"饮食不规律","type":1,"tag_id":"etccZ9HAAAtNasBp_IPYdFfphFVYoDzA"},{"group_name":"来源App标签同步2","tag_name":"体内激素失衡","type":1,"tag_id":"etccZ9HAAA9aOnamyG2uh95R43pOaWNQ"},{"group_name":"来源App标签同步2","tag_name":"普通慢性疾病","type":1,"tag_id":"etccZ9HAAAMXahRpzdoaVWuh7g7ubktA"},{"group_name":"来源App标签同步1","tag_name":"18.5≤BMI<24","type":1,"tag_id":"etccZ9HAAAtM130Q1IfEnX93uff55hbw"},{"group_name":"来源App标签同步1","tag_name":"18～22岁","type":1,"tag_id":"etccZ9HAAAOE42NKKv7Lu2SEAWqNgsug"},{"group_name":"来源App标签同步1","tag_name":"22～27岁","type":1,"tag_id":"etccZ9HAAAM6_d1HhZfR63jp9KEP4btw"},{"group_name":"来源App标签同步1","tag_name":"iPhone","type":1,"tag_id":"etccZ9HAAA6A9uHX3bQQjoydwjwc-x2Q"},{"group_name":"来源App标签同步1","tag_name":"久坐","type":1,"tag_id":"etccZ9HAAACs9XtoAtXy_LhpbD4ld4qg"},{"group_name":"来源App标签同步1","tag_name":"腰腹脂肪多","type":1,"tag_id":"etccZ9HAAA4AQE0CvtPjNQb1VanKBYKw"},{"group_name":"来源App标签同步1","tag_name":"非常需要监督","type":1,"tag_id":"etccZ9HAAAwQfubgR2sP1BwgeFd4sWnA"},{"group_name":"来源App标签同步2","tag_name":"n-3脂肪酸不足","type":1,"tag_id":"etccZ9HAAAX3StjFNPxdDrWbl7ukJujA"},{"group_name":"来源App标签同步2","tag_name":"不吃鱼虾贝类","type":1,"tag_id":"etccZ9HAAAqxF-FJ7NSLpVDfPYkkjLOA"},{"group_name":"来源App标签同步2","tag_name":"不吃鸡蛋","type":1,"tag_id":"etccZ9HAAA1snG8QlZAatY1KhD6oRhvA"},{"group_name":"来源App标签同步2","tag_name":"吃饭过快","type":1,"tag_id":"etccZ9HAAArxUsI2Xquk58CviXgl8WOw"},{"group_name":"来源App标签同步2","tag_name":"姨妈问题","type":1,"tag_id":"etccZ9HAAAXTsAFru6uJVOW_vyWgveDA"},{"group_name":"来源App标签同步2","tag_name":"常吃零食","type":1,"tag_id":"etccZ9HAAA2eanBIVvSZshMaYXLr09Ig"},{"group_name":"来源App标签同步2","tag_name":"有体检","type":1,"tag_id":"etccZ9HAAAuKjl_FvvsUsqOXkab0xXhQ"},{"group_name":"来源App标签同步2","tag_name":"蛋白质不足","type":1,"tag_id":"etccZ9HAAA8sSFWEuaOopMCoAYfIsNnw"},{"group_name":"来源App标签同步2","tag_name":"健萌会员","type":1,"tag_id":"etccZ9HAAAEditzbuq7DQG4h2cJe-yig"}],"remark_mobiles":["18692845317"],"oper_userid":"ollie","add_way":2}],"external_contact":{"unionid":"oLs8G6HfK3nBD82S4pehX08LiFFU","gender":2,"avatar":"http://wx.qlogo.cn/mmhead/K0HJuAaQ1nFrjvCbtEqAZRxUIick8pRnMSxMW0y06bnzHAhVzmichwiaMfMPwcowQpEBApULjgOZOI/0","type":1,"external_userid":"wmccZ9HAAAkleVd3k8jAMk-egp4BYLZg","name":"T."}}
        System.out.println(resultStr);
    }

    /**
     * 标签库列表
     */
    public static void tagList() {
        JSONObject body = new JSONObject();
        JSONObject resultStr = HttpUtils.sendPost("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list?access_token="+ 企业微信.postRequestWithSign(), body);
        //System.out.println(resultStr);

        JSONArray groups = resultStr.getJSONArray("tag_group");
        for(int i=0; i<groups.size(); i++){
            JSONObject group = groups.getJSONObject(i);
            String groupName = group.getStr("group_name");
            if(groupName.startsWith("来源App标签同步2")){
                JSONArray tags = group.getJSONArray("tag");
                for(int j=0; j<tags.size(); j++){
                    JSONObject tag = tags.getJSONObject(j);
                    System.out.println("update weapp_weiban_tag set qw_tag_id='"+tag.getStr("id")+"' where tag_group_name='"+groupName+"' and tag_name='"+tag.getStr("name")+"';");
                }
            }

        }

    }

    /**
     * 编辑客户标签
     */
    public static void markTag() {
        JSONObject body = new JSONObject();
        body.set("userid", "yanglin");
        body.set("external_userid", "wmccZ9HAAAkleVd3k8jAMk-egp4BYLZg");
        body.set("add_tag", new String[]{"etccZ9HAAAcu30OXX69t0SiMSvOgNABA"});
        body.set("remove_tag", new String[]{"etccZ9HAAA_-nb7zK7L5hMtJI8oiTYyg"});

        JSONObject resultStr = HttpUtils.sendPost("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token="+ 企业微信.postRequestWithSign(), body);
        System.out.println(resultStr);

    }


    class yy {
        List<Heard> heards = new ArrayList<>();//头部
        List<Data> datas = new ArrayList<>();//数据

    }

    class Heard{
        private String key; //时间：“2024-09-27”
        private String name; //星期几
    }
    class Data{
        private String empName;//员工名字
        private Map<String, List<Yy>> element;//用的Heard.key
    }
     class Yy{
        private String name; //约装/直播间
         private Date startDate;
         private Date endDate;
         private List<Object> type; //身份：岗位
     }
}
